#include "ConcurrentAlloc.h"
#include <vector>

void Alloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = ConCurrentAlloc(6);
		v.push_back(ptr);
	}
	for (auto e : v)
	{
		ConCurrentDelAlloc(e);
	}
}

void Alloc2()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = ConCurrentAlloc(7);
		v.push_back(ptr);
	}
	for (auto e : v)
	{
		ConCurrentDelAlloc(e);
	}
}


void TLSTest()
{
	std::thread t1(Alloc1);
	std::thread t2(Alloc2);
	t1.join();
	t2.join();
}


void Alloc3()
{
	for (int i = 0; i < 1024; i++)
	{
		void* ptr = ConCurrentAlloc(8);
		std::cout <<i+1<<" " << ptr << std::endl;
	}

	std::cout << std::endl;
	void* ptr1 = ConCurrentAlloc(8);
	std::cout << ptr1 << std::endl;
}

void Alloc4()
{
	void* ptr1 = ConCurrentAlloc(8);
	void* ptr2 = ConCurrentAlloc(8);
	void* ptr3 = ConCurrentAlloc(8);
	void* ptr4 = ConCurrentAlloc(8);
	void* ptr5 = ConCurrentAlloc(8);
	void* ptr6 = ConCurrentAlloc(8);
	void* ptr7 = ConCurrentAlloc(8);
	std::cout<< ptr1 << std::endl;
	std::cout<< ptr2 << std::endl;
	std::cout<< ptr3 << std::endl;
	std::cout<< ptr4 << std::endl;
	std::cout<< ptr5 << std::endl;
	std::cout<< ptr6 << std::endl;
	std::cout<< ptr7 << std::endl;


	ConCurrentDelAlloc(ptr1);
	ConCurrentDelAlloc(ptr2);
	ConCurrentDelAlloc(ptr3);
	ConCurrentDelAlloc(ptr4);
	ConCurrentDelAlloc(ptr5);
	ConCurrentDelAlloc(ptr6);
	ConCurrentDelAlloc(ptr7);
}

void Alloc5()
{
	void* ptr1 = ConCurrentAlloc(257*1024);
	ConCurrentDelAlloc(ptr1);
}

//int main()
//{
//	
//	Alloc4();
//	
//
//	return 0;
//}